package order

import (
	"fmt"
	model "service/model/crm_order"
	"service/model/mod"

	com "gitee.com/cloudapex/protos/comm/pb"

	"gitee.com/cloudapex/ulern/util"

	gpb "gitee.com/cloudapex/protos/crm_order/pb"
	"gitee.com/cloudapex/ulern/htp"
	"github.com/gin-gonic/gin"

	"context"
)

// 下单公共入参表
type CommOrderInParam struct {
	CsId      int64          `form:"csId" json:"csId" binding:"omitempty"`         // 客户Id
	OrderId   string         `form:"orderId" json:"orderId" binding:"omitempty"`   // 订单号
	Phone     string         `form:"phone" json:"phone" binding:"omitempty"`       // 手机号
	PriceBgn  int64          `form:"priceBgn" json:"priceBgn" binding:"omitempty"` // 下单金额Bgn
	PriceEnd  int64          `form:"priceEnd" json:"priceEnd" binding:"omitempty"` // 下单金额End
	ProjId    int64          `form:"projId" json:"projId" binding:"omitempty"`     // 项目Id
	OrderType mod.EOrderType `form:"orderTyp" json:"orderTyp" binding:"omitempty"` // 订单类型
	PayType   mod.EPayType   `form:"payTyp" json:"payTyp" binding:"omitempty"`     // 支付类型	// 1全款 2尾款 3定金
	Refund    int            `form:"refund" json:"refund" binding:"omitempty"`     // 是否退费(0:全部 1:否,2:是)

	OrderBgn int64 `form:"orderBgn" json:"orderBgn" binding:"omitempty"` // 下单时间(int)
	OrderEnd int64 `form:"orderEnd" json:"orderEnd" binding:"omitempty"` // 下单时间(int)
	PayBgn   int64 `form:"payBgn" json:"payBgn" binding:"omitempty"`     // 支付时间(int)
	PayEnd   int64 `form:"payEnd" json:"payEnd" binding:"omitempty"`     // 支付时间(int)
}

// 下单公共出参表
type CommOrderOutParam struct {
	Id          int64           `json:"orderId"`    // 订单ID(主键)
	CoId        int64           `json:"commpId"`    // 公司ID
	CustomerId  int64           `json:"customerId"` // 客户ID
	Phone       string          `json:"phone"`      // 手机号
	BillNo      string          `json:"billNo"`     // 订单号
	BillType    mod.EPayType    `json:"billType"`   // 1全款 2尾款 3定金
	PayType     mod.EPayWay     `json:"payType"`    // 支付方式
	UserId      int64           `json:"userId"`     // 成单坐席
	UserName    string          `json:"userName"`   // 成单坐席_
	TeachId     int64           `json:"teachId"`    // 班主任
	TeachName   string          `json:"teachName"`  // 班主任_
	ShowId      uint64          `json:"showId"`     // 所属组织ID
	ShowName    string          `json:"showName"`   // 所属组织ID_
	TotalPrice  int64           `json:"totalPrice"` // 实际支付价格
	CreatedAt   int64           `json:"createdAt"`  // 订单下单时间
	PayAt       int64           `json:"payAt"`      // 订单支付时间
	Notes       string          `json:"notes"`      // 订单通用备注
	Status      mod.EOrderState `json:"status"`     // 订单状态		// 1 未支付 2 已支付 3 已分配 4已驳回 5手动取消 6自动取消
	CancelAt    int64           `json:"cancelAt"`   // 订单取消时间
	RejectAt    int64           `json:"reasonAt"`   // 订单驳回时间
	RejectCause string          `json:"reason"`     // 订单驳回原因
	OrderType   int64           `json:"orderType"`  // 订单类型
}

/**
 *说明：订单下单
 * 路由: order/ply_order
 * 方法: POST
 */
type CrmOrderCreate struct {
	Items []CrmOrderItem `form:"items" json:"items"`
}
type CrmOrderItem struct {
	OrderId     int64       `form:"orderId" json:"orderId" binding:"omitempty"`       // 订单ID (非必传)
	CommpId     int64       `form:"commpId" json:"commpId" binding:"omitempty"`       // 公司ID
	Phone       string      `form:"phone" json:"phone" binding:"omitempty"`           // 手机号
	BillNo      string      `form:"billNo" json:"billNo" binding:"omitempty"`         // 订单单号  (非必传)
	BillType    int64       `form:"billType" json:"billType" binding:"omitempty"`     // 单号类型  1 全款 2 尾款 3 定金
	CustomerId  uint64      `form:"customerId" json:"customerId" binding:"omitempty"` // 客户ID
	PlaceId     int64       `form:"placeId" json:"placeId" binding:"omitempty"`       // 下单人
	UserId      int64       `form:"userId" json:"userId" binding:"omitempty"`         // 成单坐席
	ShowId      uint64      `form:"showId" json:"showId" binding:"omitempty"`         // 所属组织ID
	RoleId      int64       `form:"roleId" json:"roleId" binding:"omitempty"`         // 所属角色IDx
	TotalPrice  int64       `form:"totalPrice" json:"totalPrice" binding:"omitempty"` // 实际支付价格
	OrderType   int64       `form:"orderType" json:"orderType" binding:"omitempty"`   // 订单类型 1 网课  2 学历  3 证书 4 代报名 5其他待定
	Notes       string      `form:"notes" json:"notes" binding:"omitempty"`           // 订单通用备注
	Infos       []OrderInfo `form:"infos" json:"infos"`
	ParentOrder string      `form:"parentOrder" json:"parentOrder" binding:"omitempty"` //母订单单号
}

//订单详情信息入参数
type OrderInfo struct {
	//*********************start网课班型信息************************
	ProjectId   int64  `form:"projectId" json:"projectId" binding:"omitempty"`     //项目ID
	ProjectName string `form:"projectName" json:"projectName" binding:"omitempty"` //项目名称
	ClassId     int64  `form:"classId" json:"classId" binding:"omitempty"`         //班型ID
	ClassName   string `form:"className" json:"className" binding:"omitempty"`     //班型名称
	//*********************start学历信息************************
	SchoolId    int64  `form:"schoolId" json:"schoolId" binding:"omitempty"`       //学校ID
	SchoolName  string `form:"schoolName" json:"schoolName" binding:"omitempty"`   //学校名称
	MajorId     int64  `form:"majorId" json:"majorId" binding:"omitempty"`         //专业ID
	MajorName   string `form:"majorName" json:"majorName" binding:"omitempty"`     //专业名称
	MStatus     int64  `form:"mStatus" json:"mStatus" binding:"omitempty"`         //专业分类
	SStatus     int64  `form:"sStatus" json:"sStatus" binding:"omitempty"`         //学历分类
	StudentName string `form:"studentName" json:"studentName" binding:"omitempty"` //学员姓名
	IdCard      string `form:"idCard" json:"idCard" binding:"omitempty"`           //学员身份证号
	Address     string `form:"address" json:"address" binding:"omitempty"`         //学员户籍地址
	//*********************start证书信息************************
	CertName string `form:"certName" json:"certName" binding:"omitempty"` //证书名称
	//*********************start报名信息************************
	OAddress string `form:"oAddress" json:"oAddress" binding:"omitempty"` //取证地址
	//*********************end报名信息**************************
	Price    int64 `form:"price" json:"price" binding:"omitempty"`       //网课价格
	OStatus  int64 `form:"oStatus" json:"oStatus" binding:"omitempty"`   //是否退费
	OChange  int64 `form:"oChange" json:"oChange" binding:"omitempty"`   //是否换课
	OClose   int64 `form:"oClose" json:"oClose" binding:"omitempty"`     //是否关课
	UpdateAt int64 `form:"updateAt" json:"updateAt" binding:"omitempty"` //时间
}

func (this *CrmOrderCreate) Handle(c *gin.Context, ctx context.Context) htp.Response {
	var orders []*gpb.CrmOrderCreateReq
	jwtUser := mod.CurrUser(c)
	var userid int64
	var roleId int64
	for n, it := range this.Items {
		userid = it.PlaceId
		if it.PlaceId == 0 {
			userid = jwtUser.UId
		}
		roleId = it.RoleId
		if it.RoleId == 0 {
			roleId = jwtUser.RoleId
		}
		orders = append(orders, &gpb.CrmOrderCreateReq{
			CommpId:     jwtUser.CId,
			Phone:       it.Phone,
			BillType:    it.BillType,
			CustomerId:  it.CustomerId,
			PlaceId:     jwtUser.UId,
			UserId:      userid,
			ShowId:      jwtUser.ShowId[0],
			RoleId:      roleId,
			TotalPrice:  it.TotalPrice,
			OrderType:   it.OrderType,
			Notes:       it.Notes,
			ParentOrder: it.ParentOrder,
		})
		for _, ia := range it.Infos {
			orders[n].InfoList = append(orders[n].InfoList, &gpb.CrmOrderInfoReq{
				ProjectId:   ia.ProjectId,
				ProjectName: ia.ProjectName,
				ClassId:     ia.ClassId,
				ClassName:   ia.ClassName,
				SchoolId:    ia.SchoolId,
				SchoolName:  ia.SchoolName,
				MajorId:     ia.MajorId,
				MajorName:   ia.MajorName,
				MStatus:     ia.MStatus,
				SStatus:     ia.SStatus,
				StudentName: ia.StudentName,
				IdCard:      ia.IdCard,
				Address:     ia.Address,
				CertName:    ia.CertName,
				OAddress:    ia.OAddress,
				Price:       ia.Price,
				OStatus:     ia.OStatus,
				OChange:     ia.OChange,
				OClose:      ia.OClose,
				UpdateAt:    ia.UpdateAt,
			})
		}
	}
	crmoder := gpb.CrmOrderCreateListReq{OrderList: orders}
	_, err := model.Order.CrmOrderCreate(ctx, &crmoder)
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", nil)

}

/*
	描述 ：判断是否有订单定金订单未支付
	路由 ：order/deposit
	方法 ：POST
*/

type OrderUCList struct {
	mod.SortFinder // 1:下单金额 2:下单时间 3:支付时间
	//mod.PageFinder
	Pnum             int64 `form:"pnum" json:"pnum" binding:"omitempty"` // 单页数量
	Page             int64 `form:"page" json:"page" binding:"omitempty"` // 页码
	CommOrderInParam       // 公共参数(见上面结构)
	Repair           int64 `json:"repair" form:"repair" binding:"omitempty"` //是否有补过 定金的尾款状态   1  没补过  2已补过

	State mod.EOrderState `form:"state" json:"state" binding:"required"` // 订单状态
}

type orderBRspItem struct {
	CommOrderOutParam // 公共参数(见上面结构)

	Details []*model.CrmOrderInfo `json:"details"` // 订单下的网课详情
}

func (this *OrderUCList) Handle(c *gin.Context, ctx context.Context) htp.Response {
	user := mod.CurrUser(c)
	var state []int64
	state = append(state, int64(this.State)) // 正确的
	if this.State == 100 {
		state = []int64{}
		for i := mod.EOrderS_NoPay; i <= mod.EOrderS_AutoCancel; i++ {
			state = append(state, int64(i))
		}
	}
	rsp, err := model.Order.CrmOrderList(ctx, &gpb.CrmOrderListReq{
		Page:       1,
		Count:      100,
		Order:      int64(this.SortFinder.Order),
		Orule:      int64(this.SortFinder.Orule + 1),
		CommpId:    user.CId,
		CustomerId: uint64(this.CsId),
		BillNo:     this.OrderId,
		Phone:      this.Phone,
		PriceBgn:   this.PriceBgn,
		PriceEnd:   this.PriceEnd,
		ProjectId:  this.ProjId,
		OrderType:  int64(this.OrderType),
		BillType:   int64(this.PayType),
		ReFund:     int64(this.Refund),
		OrderBgn:   this.OrderBgn,
		OrderEnd:   this.OrderEnd,
		PayBgn:     this.PayBgn,
		PayEnd:     this.PayEnd,
		State:      state,
		ShowId:     user.ShowId,
		Repair:     this.Repair,
	})

	if err != nil {
		return htp.RespModelErr("_o", err)
	}
	items := []*orderBRspItem{}
	if err := util.Convert(&items, rsp.Data); err != nil {
		return htp.RespConvertErr("", err)
	}
	return htp.RespOK("", &struct {
		Total int64       `json:"total"`
		List  interface{} `json:"list"`
	}{rsp.Pager.Total, items})
}

/*
	描述 ：定金尾款下单
	路由 ：order/deposit_balance
	方法 ：POST
*/
type DepositBalance struct {
	Items []CrmOrderItem `form:"items" json:"items"`
}

func (this *DepositBalance) Handle(c *gin.Context, ctx context.Context) htp.Response {
	var orders []*gpb.CrmOrderCreateReq
	jwtUser := mod.CurrUser(c)
	var userid, roleId int64
	for n, it := range this.Items {
		userid = it.PlaceId
		if it.PlaceId == 0 {
			userid = jwtUser.UId
		}
		roleId = it.RoleId
		if it.RoleId == 0 {
			roleId = jwtUser.RoleId
		}
		orders = append(orders, &gpb.CrmOrderCreateReq{
			CommpId:     jwtUser.CId,
			Phone:       it.Phone,
			BillType:    it.BillType,
			CustomerId:  it.CustomerId,
			PlaceId:     jwtUser.UId,
			UserId:      userid,
			ShowId:      jwtUser.ShowId[0],
			RoleId:      roleId,
			TotalPrice:  it.TotalPrice,
			OrderType:   it.OrderType,
			Notes:       it.Notes,
			ParentOrder: it.ParentOrder,
		})
		for _, ia := range it.Infos {
			orders[n].InfoList = append(orders[n].InfoList, &gpb.CrmOrderInfoReq{
				ProjectId:   ia.ProjectId,
				ProjectName: ia.ProjectName,
				ClassId:     ia.ClassId,
				ClassName:   ia.ClassName,
				SchoolId:    ia.SchoolId,
				SchoolName:  ia.SchoolName,
				MajorId:     ia.MajorId,
				MajorName:   ia.MajorName,
				MStatus:     ia.MStatus,
				SStatus:     ia.SStatus,
				StudentName: ia.StudentName,
				IdCard:      ia.IdCard,
				Address:     ia.Address,
				CertName:    ia.CertName,
				OAddress:    ia.OAddress,
				Price:       ia.Price,
				OStatus:     ia.OStatus,
				OChange:     ia.OChange,
				OClose:      ia.OClose,
				UpdateAt:    ia.UpdateAt,
			})
		}
	}
	fmt.Println("--------------------", orders)
	crmoder := gpb.CrmOrderCreateListReq{OrderList: orders}
	_, err := model.Order.CrmDepositOrderCreate(ctx, &crmoder)
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", nil)
}

/*
	描述 ：学员库
	路由 ：order/student_info
	方法 ：POST
*/

type StudentItem struct {
	CustomerId uint64 `form:"csId" json:"csId" binding:"omitempty"`           //客户ID
	Phone      string `form:"phone" json:"phone" binding:"omitempty"`         //手机号
	UserId     int64  `form:"userId" json:"userId" binding:"omitempty"`       //班主任坐席
	ProjectId  int64  `form:"projectId" json:"projectId" binding:"omitempty"` //项目ID
	Senior     int64  `form:"senior" json:"senior" binding:"omitempty"`       //是否升班
	DistBgn    int64  `form:"distBgn" json:"distBgn" binding:"omitempty"`     //分配最小时间
	DistEnd    int64  `form:"distEnd" json:"distEnd" binding:"omitempty"`     //分配最大时间
	ChangeBgn  int64  `form:"changeBgn" json:"changeBgn" binding:"omitempty"` //更换最小时间
	ChangeEnd  int64  `form:"changeEnd" json:"changeEnd" binding:"omitempty"` //更换最大时间
	Page       int64  `form:"page" json:"page" binding:"omitempty"`           //页码
	Count      int64  `form:"pnum" json:"pnum" binding:"omitempty"`           //单页数量
	Total      int64  `form:"total" json:"total" binding:"omitempty"`         //总数
	Order      int64  `form:"order" json:"order" binding:"omitempty"`         //排序字段(默认空,则程序用默认字段)
	Orule      int64  `form:"orule" json:"orule" binding:"omitempty"`         //1:倒叙; 2:升序;
	PriceBgn   int64  `form:"priceBgn" json:"priceBgn" binding:"omitempty"`   //最小下单金额
	PriceEnd   int64  `form:"priceEnd" json:"priceEnd" binding:"omitempty"`   //最大下单金额
}

type Studentinfo struct {
	CommpId     int64  `json:"commpId"`     // 公司ID
	Phone       string `json:"phone"`       // 手机号
	CustomerId  uint64 `json:"customerId"`  // 客户ID
	ProjectId   int64  `json:"projectId"`   //项目ID
	ProjectName string `json:"projectName"` //项目名称
	Amount      int64  `json:"amount"`      //成交金额
	Senior      int64  `json:"senior"`      //是否升班
	UserId      uint64 `json:"userId"`      //班主任坐席ID
	UserName    string `json:"userName"`    //班主任坐席名称
	StudentId   int64  `json:"studentId"`   //学员库ID
	DistrAt     int64  `json:"distrAt"`     //分配时间
	ChangeAt    int64  `json:"changeAt"`    //更换时间
}

func (this *StudentItem) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)
	studentinfo := gpb.StudentListReq{
		CustomerId: this.CustomerId,
		Phone:      this.Phone,
		UserId:     jwtUser.UId,
		ProjectId:  this.ProjectId,
		Senior:     this.Senior,
		DistBgn:    this.DistBgn,
		DistEnd:    this.DistEnd,
		ChangeBgn:  this.ChangeBgn,
		ChangeEnd:  this.ChangeEnd,
		PriceBgn:   this.PriceBgn,
		PriceEnd:   this.PriceEnd,
		Pager: &com.PageResponse{
			Page:  this.Page,
			Count: this.Count,
			Order: this.Order,
			Orule: this.Orule + 1,
		},
	}
	rep, err := model.StudentOrder.StudentList(ctx, &studentinfo)
	if err != nil {
		return htp.RespModelErr("", err)
	}
	fmt.Println("rep : ", studentinfo)

	fmt.Println("res", rep)

	user := make([]Studentinfo, 0)
	for _, s := range rep.Data {
		var info Studentinfo
		util.Convert(&info, s)
		user = append(user, info)
	}
	return htp.RespOK("", &struct {
		Total int64       `json:"total"`
		List  interface{} `json:"list"`
	}{rep.Pager.Total, user})

}

type StudentItemG struct {
	CustomerId uint64 `form:"customerId" json:"customerId" binding:"omitempty"` //客户ID
	Phone      string `form:"phone" json:"phone" binding:"omitempty"`           //手机号
	UserId     int64  `form:"userId" json:"userId" binding:"omitempty"`         //班主任坐席
	ProjectId  int64  `form:"projectId" json:"projectId" binding:"omitempty"`   //项目ID
	Senior     int64  `form:"senior" json:"senior" binding:"omitempty"`         //是否升班
	DistBgn    int64  `form:"distBgn" json:"distBgn" binding:"omitempty"`       //分配最小时间
	DistEnd    int64  `form:"distEnd" json:"distEnd" binding:"omitempty"`       //分配最大时间
	ChangeBgn  int64  `form:"changeBgn" json:"changeBgn" binding:"omitempty"`   //更换最小时间
	ChangeEnd  int64  `form:"changeEnd" json:"changeEnd" binding:"omitempty"`   //更换最大时间
	Page       int64  `form:"page" json:"page" binding:"omitempty"`             //页码
	Count      int64  `form:"pnum" json:"pnum" binding:"omitempty"`             //单页数量
	Total      int64  `form:"total" json:"total" binding:"omitempty"`           //总数
	Order      int64  `form:"order" json:"order" binding:"omitempty"`           //排序字段(默认空,则程序用默认字段)
	Orule      int64  `form:"orule" json:"orule" binding:"omitempty"`           //1:倒叙; 2:升序;
	PriceBgn   int64  `form:"priceBgn" json:"priceBgn" binding:"omitempty"`     //最小下单金额
	PriceEnd   int64  `form:"priceEnd" json:"priceEnd" binding:"omitempty"`     //最大下单金额
}

//管理
func (this *StudentItemG) Handle(c *gin.Context, ctx context.Context) htp.Response {
	studentinfo := gpb.StudentListReq{
		CustomerId: this.CustomerId,
		Phone:      this.Phone,
		UserId:     this.UserId,
		ProjectId:  this.ProjectId,
		Senior:     this.Senior,
		DistBgn:    this.DistBgn,
		DistEnd:    this.DistEnd,
		ChangeBgn:  this.ChangeBgn,
		ChangeEnd:  this.ChangeEnd,
		PriceBgn:   this.PriceBgn,
		PriceEnd:   this.PriceEnd,
		Pager: &com.PageResponse{
			Page:  this.Page,
			Count: this.Count,
			Order: this.Order,
			Orule: this.Orule + 1,
		},
	}
	rep, err := model.StudentOrder.StudentList(ctx, &studentinfo)
	if err != nil {
		return htp.RespModelErr("", err)
	}
	fmt.Println("rep : ", studentinfo)

	user := make([]Studentinfo, 0)
	for _, s := range rep.Data {
		var info Studentinfo
		util.Convert(&info, s)
		user = append(user, info)
	}
	return htp.RespOK("", &struct {
		Total int64       `json:"total"`
		List  interface{} `json:"list"`
	}{rep.Pager.Total, user})

}

/*
	查询该订单下是否支付过尾款和定金订单
*/
type OrderDepsitBla struct {
	BillNo      string  `json:"billNo" form:"billNo" binding:"omitempty"`           //账单号 （订单号）
	OrderId     int64   `json:"orderId" form:"orderId" binding:"omitempty"`         //订单ID （订单ID）
	ParentOrder string  `json:"parentOrder" form:"parentOrder" binding:"omitempty"` //母订单单号 （订单号）
	BillTypeArr []int64 `json:"billTypeArr" form:"billTypeArr" binding:"omitempty"` //订单类型 切片 (全款尾款定金)
	Status      int64   `json:"status" form:"status" binding:"omitempty"`           //订单状态 （已支付未支付）
}

type OrderDepsitBlaItem struct {
	OrderId    int64  `json:"orderId"`    // 订单ID
	CommpId    int64  `json:"commpId"`    // 公司ID
	Phone      string `json:"phone"`      // 手机号
	BillNo     string `json:"billNo"`     // 订单单号
	BillType   int64  `json:"billType"`   // 单号类型  1 全款 2 尾款 3 定金
	CustomerId int64  `json:"customerId"` // 客户ID
	PlaceId    int64  `json:"placeId"`    // 下单人
	UserId     int64  `json:"userId"`     // 成单坐席
	ShowId     uint64 `json:"showId"`     // 所属组织ID
	TotalPrice int64  `json:"totalPrice"` // 实际支付价格
	OrderType  int64  `json:"orderType"`  // 订单类型 1 网课  2 学历  3 证书 4 代报名 5其他待定
	CreatedAt  int64  `json:"createdAt"`  // 订单下单时间
	Status     int64  `json:"status"`     // 订单状态  1 未支付  2 已支付  3 已分配 4 已驳回 5手动取消 6自动取消
}

func (this *OrderDepsitBla) Handle(c *gin.Context, ctx context.Context) htp.Response {
	rsp, err := model.Order.CrmOrderDepsitBla(ctx, &gpb.CrmOrderGetReq{
		BillNo:      this.BillNo,
		OrderId:     this.OrderId,
		ParentOrder: this.ParentOrder,
		BillTypeArr: this.BillTypeArr,
		Status:      this.Status,
	})
	if nil != err {
		return htp.RespModelErr("", err)
	}
	fmt.Println("----------------------")
	fmt.Println(rsp)
	fmt.Println("----------------------")
	items := &OrderDepsitBlaItem{}
	if err := util.Convert(&items, rsp); nil != err {
		return htp.RespConvertErr("", err)
	}
	return htp.RespOK("", &struct {
		List interface{} `json:"list"`
	}{items})
}

/*
	说明：查询子订单列表
*/

type CrmSubOrderReq struct {
	BillNo      string  `json:"billNo" form:"billNo" binding:"omitempty"`           //账单号 （订单号）
	OrderId     int64   `json:"orderId" form:"orderId" binding:"omitempty"`         //订单ID （订单ID）
	ParentOrder string  `json:"parentOrder" form:"parentOrder" binding:"omitempty"` //母订单单号 （订单号）
	BillTypeArr []int64 `json:"billTypeArr" form:"billTypeArr" binding:"omitempty"` //订单类型 切片 (全款尾款定金)
	Status      int64   `json:"status" form:"status" binding:"omitempty"`           //订单状态 （已支付未支付）
}

func (this *CrmSubOrderReq) Handle(c *gin.Context, ctx context.Context) htp.Response {
	rsp, err := model.Order.CrmSubOrderList(ctx, &gpb.CrmOrderGetReq{
		BillNo:      this.BillNo,
		OrderId:     this.OrderId,
		ParentOrder: this.ParentOrder,
		BillTypeArr: this.BillTypeArr,
		Status:      this.Status,
	})
	if nil != err {
		return htp.RespModelErr("", err)
	}
	items := []*orderBRspItem{}
	if err := util.Convert(&items, rsp.Data); err != nil {
		return htp.RespConvertErr("", err)
	}
	return htp.RespOK("", &struct {
		List interface{} `json:"list"`
	}{items})
}
